class StorageFn {
	constructor () {
		this.ls = window.localStorage;
		this.ss = window.sessionStorage;
	}
	/* --------- cookie  ------------- */
	/* 设置 cookie */
	setCookie(name,value,day) {
		var setting = arguments[0];
		if (Object.prototype.toString.call(setting).slice(8,-1) === 'Object') {
			for(var i in setting) {
				var oDate = new Date();
				oDate.setDate(oDate.getDate() + day);
				document.cookie = name + '=' + value + ';expires=' + oDate;
			}
		} else {
			var oDate = new Date();
			oDate.setDate(oDate.getDate() + day);
			document.cookie = name + '=' + value + ';expires='+ oDate;
		}
	}
	/* 获取cookie */
	getCookie(name) {
		var arr = document.cookit.split(';');
		for (var i = 0;i< arr.length;i++) {
			var arr2 = arr[i].split('=');
			if (arr2[0] == name) {
				return arr2[1];
			}
		}
		return '';
	}
	/* 删除cookie */
	removeCookit(name) {
		this.setCookie(name,1,-1);
	}
	/* --------- localstorage  ------------- */
	/* 设置 localstorage */

	setLocal(key,val) {
		var setting = arguments[0];
		if (Object.prototype.toString.call(setting).slice(8,-1) === 'Object') {
			for (let i in object) {
				this.ls.setItem(i,JSON.stringify(setting[i]))
			}
		} else {
			this.ls.setItem(key,JSON.stringify(val))
		}
	}
	/* 获取 localstorage */
	getLoacl(key) {
		if (key) {
			return JSON.parse(this.ls.getItem(key));
		} else {
			return null;
		}
	}
	/* 移除 localstorage */
	remveLoacl(key) {
		this.ls.removeItem(key)
	}
	/* 移除 所有 localstorage */
	clearLoacl() {
		this.ls.clear();
	}
	/* --------- sessionStorage  ------------- */
	/* 设置 sessionStorage */
	setSession(key,vak) {
		var setting = arguments[0];
		if(Object.prototype.toString.call(setting).slice(8,-1) === 'Object') {
			for (let i in object) {
				this.ss.setItem(i,JSON.stringify(setting[i]))
			}
		} else {
			this.ss.setItem(key,JSON.stringify(val))
		}
	}
	/* 获取 sessionStorage */
	getSession(key) {
		if (key) {
			return JSON.parse(this.ss.getItem(key))
		} else {
			return null
		}
	}
	/* 移除 sessionStorage */
	removeSession(key) {
		this.ss.removeItem(key)
	}
	/* 移除所有 sessionStorage */
	clearSession() {
		this.ss.clear();
	}
}